import pytest
from common.request_util_test import RequestUtil
from common.test_yaml_util_test import YamlUtil
from config import datas


class Testnode:
    url_unify = "/clusters/host"

    @pytest.mark.normal
    @pytest.mark.k8sresource
    @pytest.mark.node
    @pytest.mark.parametrize('nodeinfo',
                             YamlUtil().read_testcase_yaml('v25.06/resourcemanage/node/1_get_node_list.yaml'))
    def test_get_node_list(self, nodeinfo):
        # 获取node列表接口-正常
        base_url = datas.baseUrl + Testnode.url_unify
        url = base_url + nodeinfo['request']['url']
        method = nodeinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == nodeinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.k8sresource
    @pytest.mark.node
    @pytest.mark.parametrize('nodeinfo',
                             YamlUtil().read_testcase_yaml('v25.06/resourcemanage/node/2_get_specific_node.yaml'))
    def test_get_specific_node(self, nodeinfo):
        # 获取指定的node-正常
        base_url = datas.baseUrl + Testnode.url_unify
        url = base_url + nodeinfo['request']['url'].replace('{nodename}', datas.HOST_NAME)
        method = nodeinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == nodeinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.k8sresource
    @pytest.mark.node
    @pytest.mark.parametrize('nodeinfo',
                             YamlUtil().read_testcase_yaml('v25.06/resourcemanage/node/1_get_node_list_exception.yaml'))
    def test_get_node_list_exception(self, nodeinfo):
        # 获取node列表接口-异常
        base_url = datas.baseUrl + Testnode.url_unify
        url = base_url + nodeinfo['request']['url']
        method = nodeinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == nodeinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.k8sresource
    @pytest.mark.node
    @pytest.mark.parametrize('nodeinfo', YamlUtil().read_testcase_yaml(
        'v25.06/resourcemanage/node/2_get_specific_node_exception.yaml'))
    def test_get_specific_node_exception(self, nodeinfo):
        # 获取指定的node-异常
        base_url = datas.baseUrl + Testnode.url_unify
        url = base_url + nodeinfo['request']['url'].replace('{nodename}', datas.HOST_NAME)
        method = nodeinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == nodeinfo['validate'][0]['equals']['status_code']
